package com.example.project_board.controller;


import com.example.project_board.mapper.UserMapper;
import com.example.project_board.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller

public class Reg {
    @Autowired
    UserMapper userMapper;
    @RequestMapping("/register")
    @ResponseBody
    public Object addCusumer(@RequestParam Map<String, Object> params)
    {
        String userid = (String) params.get("userid");
        String userpassword = (String) params.get("userpassword");
        String password = (String) params.get("password2");

//        cusumer.setUserid(userid);
//        cusumer.setUserpassword(userpassword);
//        cusumerMapper.insertCusumer(cusumer);

        String a = userMapper.selectuser(userid);
        if (a != null && !a.equals("") || password.equals("") || password.equals("null")){
            return new ModelAndView("regError");
        }else{
            User user = new User();
            user.setUserid(userid);
            user.setUserpassword(userpassword);
            userMapper.insertUser(user);
            return new ModelAndView("userlogin");
        }
//        return new ModelAndView("login");

    }
}
